using System;
using Peepster.Core;

namespace Peepster.Infrastructure.Twitter
{
    /// <summary>
    /// Source: http://code.google.com/p/twitterizer/
    /// Getting Started: http://code.google.com/p/twitterizer/wiki/GettingStarted
    /// </summary>
    public class TwitterizerTwitterService : ITwitterService
    {
        private Twitterizer.Framework.Twitter _service;

        public TwitterizerTwitterService()
        {
            _service = new Twitterizer.Framework.Twitter(
                AppSettings.TwitterUserName, 
                AppSettings.TwitterPassword,
                AppSettings.ClientName);
        }

        public void SendTweet(string message)
        {
            try
            {
                _service.Status.Update(message);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Unable to send tweet\n" + e.Message);
            }
        }

        public bool ValidateAccount(string userName, string password)
        {
            try
            {
                _service.Status.Mentions();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}